//Ajax

function get(url, success) {

    showLoad(1);
    layui.jquery.ajax({
        url: url,
        type: "GET",
        success: success
    });

}

function post(url, data, success) {

    showLoad(1);
    layui.jquery.ajax({
        url: url,
        type: "POST",
        data: {json: JSON.stringify(data)},
        success: success
    });

}

function postNormal(url, data, success) {

    showLoad(1);
    layui.jquery.ajax({
        url: url,
        type: "POST",
        data: data,
        success: success
    });

}

//Json

function jsonMsg(json) {

    return json.msg;

}

function jsonCode(json) {

    return json.code;

}

function jsonData(json) {

    return json.data;

}

function jsonFailure(json) {

    return json.code === "2";

}

function jsonSuccess(json) {

    return json.code === "1" && json.data === "1";

}

//Dialog

function closeAll() {

    layui.use("layer", function () {
        layui.layer.closeAll("loading");
    });

}

function showLoad(style) {

    layui.use("layer", function () {
        layui.layer.load(style);
    });

}

function showIFrame(title, url) {

    layui.use("layer", function () {
        layui.layer.open({
            type: 2,
            offset: "80px",
            title: title,
            shadeClose: false,
            closeBtn: 2,
            area: ["700px", "700px"],
            content: [url, "no"],
        });
    });

}

function showMessage(message, icon, func) {

    layui.use("layer", function () {
        layui.layer.msg(message, {icon: icon, shade: 0, time: 2000}, func);
    });

}

function showMessageFailure() {

    layui.use("layer", function () {
        layui.layer.msg("失败！", {icon: 2, shade: 0, time: 2000});
    });

}

function showMessageSuccess() {

    layui.use("layer", function () {
        layui.layer.msg("成功！", {icon: 1, shade: 0, time: 2000});
    });

}

//Other

function isEmpty(str) {

    return str === null || str === undefined || str === "";

}

function getCookie(name) {

    if (document.cookie.length > 0) {
        start = document.cookie.indexOf(name + "=");
        if (start !== -1) {
            start = start + name.length + 1;
            end = document.cookie.indexOf(";", start);
            if (end === -1) end = document.cookie.length;
            return unescape(document.cookie.substring(start, end));
        }
    }
    return "";

}

function setCookie(name, value) {

    document.cookie = name + "=" + escape(value) + "";

}

function getParamValue(name) {

    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    let r = window.location.search.substr(1).match(reg);
    if (r !== null) return unescape(r[2]);
    return null;

}

function handlerDate(date) {

    if (isEmpty(date)) return "";
    date = date.replace("-", "年");
    date = date.replace("-", "月");
    if (date.indexOf("日") === -1) date = date + "日";
    return date;

}
